package 类型转换;

public class Main {
    public static void main(String[] args) {
        //自动类型转换  子类到父类
        Animals dog = new Dog();


        //强制类型转换  父类到子类
        Animals dog2 = new Dog();
        dog2.run();
        Dog dog3 = (Dog)dog2;
        dog3.lookdoor();
        Animals cat = new Cat();
        go(dog3);
        go(cat);
    }

    public static void go(Animals a){
        if(a instanceof Dog){
            Dog d = (Dog)a;
            d.lookdoor();
        }else{
            System.out.println("这不是狗");
        }
    }
}
